package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomTransactionProperty;
import com.room.search.repository.RoomTransactionPropertyRepository;
import com.room.search.service.dto.RoomTransactionPropertyDTO;
import com.room.search.service.mapper.RoomTransactionPropertyMapper;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link RoomTransactionPropertyResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomTransactionPropertyResourceIT {

    private static final LocalDate DEFAULT_LISTING_TIME = LocalDate.ofEpochDay(0L);
    private static final LocalDate UPDATED_LISTING_TIME = LocalDate.now(ZoneId.systemDefault());

    private static final LocalDate DEFAULT_LAST_TRADE_TIME = LocalDate.ofEpochDay(0L);
    private static final LocalDate UPDATED_LAST_TRADE_TIME = LocalDate.now(ZoneId.systemDefault());

    private static final String DEFAULT_ROOM_AGE_LIMIT = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_AGE_LIMIT = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_MORTGAGE = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_MORTGAGE = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_TRANSACTION_OWNERSHIP = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_TRANSACTION_OWNERSHIP = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_USER = "AAAAAAAA";
    private static final String UPDATED_ROOM_USER = "BBBBBBBB";

    private static final String DEFAULT_ROOM_PROPERTY_RIGHTS = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_PROPERTY_RIGHTS = "BBBBBBBBBB";

    private static final String DEFAULT_ROOM_SPARE_PARTS = "AAAAAAAAAA";
    private static final String UPDATED_ROOM_SPARE_PARTS = "BBBBBBBBBB";

    private static final String ENTITY_API_URL = "/api/room-transaction-properties";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomTransactionPropertyRepository roomTransactionPropertyRepository;

    @Autowired
    private RoomTransactionPropertyMapper roomTransactionPropertyMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomTransactionPropertyMockMvc;

    private RoomTransactionProperty roomTransactionProperty;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomTransactionProperty createEntity(EntityManager em) {
        RoomTransactionProperty roomTransactionProperty = new RoomTransactionProperty()
            .listingTime(DEFAULT_LISTING_TIME)
            .lastTradeTime(DEFAULT_LAST_TRADE_TIME)
            .roomAgeLimit(DEFAULT_ROOM_AGE_LIMIT)
            .roomMortgage(DEFAULT_ROOM_MORTGAGE)
            .roomTransactionOwnership(DEFAULT_ROOM_TRANSACTION_OWNERSHIP)
            .roomUser(DEFAULT_ROOM_USER)
            .roomPropertyRights(DEFAULT_ROOM_PROPERTY_RIGHTS)
            .roomSpareParts(DEFAULT_ROOM_SPARE_PARTS);
        return roomTransactionProperty;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomTransactionProperty createUpdatedEntity(EntityManager em) {
        RoomTransactionProperty roomTransactionProperty = new RoomTransactionProperty()
            .listingTime(UPDATED_LISTING_TIME)
            .lastTradeTime(UPDATED_LAST_TRADE_TIME)
            .roomAgeLimit(UPDATED_ROOM_AGE_LIMIT)
            .roomMortgage(UPDATED_ROOM_MORTGAGE)
            .roomTransactionOwnership(UPDATED_ROOM_TRANSACTION_OWNERSHIP)
            .roomUser(UPDATED_ROOM_USER)
            .roomPropertyRights(UPDATED_ROOM_PROPERTY_RIGHTS)
            .roomSpareParts(UPDATED_ROOM_SPARE_PARTS);
        return roomTransactionProperty;
    }

    @BeforeEach
    public void initTest() {
        roomTransactionProperty = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeCreate = roomTransactionPropertyRepository.findAll().size();
        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);
        restRoomTransactionPropertyMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeCreate + 1);
        RoomTransactionProperty testRoomTransactionProperty = roomTransactionPropertyList.get(roomTransactionPropertyList.size() - 1);
        assertThat(testRoomTransactionProperty.getListingTime()).isEqualTo(DEFAULT_LISTING_TIME);
        assertThat(testRoomTransactionProperty.getLastTradeTime()).isEqualTo(DEFAULT_LAST_TRADE_TIME);
        assertThat(testRoomTransactionProperty.getRoomAgeLimit()).isEqualTo(DEFAULT_ROOM_AGE_LIMIT);
        assertThat(testRoomTransactionProperty.getRoomMortgage()).isEqualTo(DEFAULT_ROOM_MORTGAGE);
        assertThat(testRoomTransactionProperty.getRoomTransactionOwnership()).isEqualTo(DEFAULT_ROOM_TRANSACTION_OWNERSHIP);
        assertThat(testRoomTransactionProperty.getRoomUser()).isEqualTo(DEFAULT_ROOM_USER);
        assertThat(testRoomTransactionProperty.getRoomPropertyRights()).isEqualTo(DEFAULT_ROOM_PROPERTY_RIGHTS);
        assertThat(testRoomTransactionProperty.getRoomSpareParts()).isEqualTo(DEFAULT_ROOM_SPARE_PARTS);
    }

    @Test
    @Transactional
    void createRoomTransactionPropertyWithExistingId() throws Exception {
        // Create the RoomTransactionProperty with an existing ID
        roomTransactionProperty.setId(1L);
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        int databaseSizeBeforeCreate = roomTransactionPropertyRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomTransactionPropertyMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomTransactionProperties() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        // Get all the roomTransactionPropertyList
        restRoomTransactionPropertyMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomTransactionProperty.getId().intValue())))
            .andExpect(jsonPath("$.[*].listingTime").value(hasItem(DEFAULT_LISTING_TIME.toString())))
            .andExpect(jsonPath("$.[*].lastTradeTime").value(hasItem(DEFAULT_LAST_TRADE_TIME.toString())))
            .andExpect(jsonPath("$.[*].roomAgeLimit").value(hasItem(DEFAULT_ROOM_AGE_LIMIT)))
            .andExpect(jsonPath("$.[*].roomMortgage").value(hasItem(DEFAULT_ROOM_MORTGAGE)))
            .andExpect(jsonPath("$.[*].roomTransactionOwnership").value(hasItem(DEFAULT_ROOM_TRANSACTION_OWNERSHIP)))
            .andExpect(jsonPath("$.[*].roomUser").value(hasItem(DEFAULT_ROOM_USER)))
            .andExpect(jsonPath("$.[*].roomPropertyRights").value(hasItem(DEFAULT_ROOM_PROPERTY_RIGHTS)))
            .andExpect(jsonPath("$.[*].roomSpareParts").value(hasItem(DEFAULT_ROOM_SPARE_PARTS)));
    }

    @Test
    @Transactional
    void getRoomTransactionProperty() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        // Get the roomTransactionProperty
        restRoomTransactionPropertyMockMvc
            .perform(get(ENTITY_API_URL_ID, roomTransactionProperty.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomTransactionProperty.getId().intValue()))
            .andExpect(jsonPath("$.listingTime").value(DEFAULT_LISTING_TIME.toString()))
            .andExpect(jsonPath("$.lastTradeTime").value(DEFAULT_LAST_TRADE_TIME.toString()))
            .andExpect(jsonPath("$.roomAgeLimit").value(DEFAULT_ROOM_AGE_LIMIT))
            .andExpect(jsonPath("$.roomMortgage").value(DEFAULT_ROOM_MORTGAGE))
            .andExpect(jsonPath("$.roomTransactionOwnership").value(DEFAULT_ROOM_TRANSACTION_OWNERSHIP))
            .andExpect(jsonPath("$.roomUser").value(DEFAULT_ROOM_USER))
            .andExpect(jsonPath("$.roomPropertyRights").value(DEFAULT_ROOM_PROPERTY_RIGHTS))
            .andExpect(jsonPath("$.roomSpareParts").value(DEFAULT_ROOM_SPARE_PARTS));
    }

    @Test
    @Transactional
    void getNonExistingRoomTransactionProperty() throws Exception {
        // Get the roomTransactionProperty
        restRoomTransactionPropertyMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomTransactionProperty() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();

        // Update the roomTransactionProperty
        RoomTransactionProperty updatedRoomTransactionProperty = roomTransactionPropertyRepository
            .findById(roomTransactionProperty.getId())
            .get();
        // Disconnect from session so that the updates on updatedRoomTransactionProperty are not directly saved in db
        em.detach(updatedRoomTransactionProperty);
        updatedRoomTransactionProperty
            .listingTime(UPDATED_LISTING_TIME)
            .lastTradeTime(UPDATED_LAST_TRADE_TIME)
            .roomAgeLimit(UPDATED_ROOM_AGE_LIMIT)
            .roomMortgage(UPDATED_ROOM_MORTGAGE)
            .roomTransactionOwnership(UPDATED_ROOM_TRANSACTION_OWNERSHIP)
            .roomUser(UPDATED_ROOM_USER)
            .roomPropertyRights(UPDATED_ROOM_PROPERTY_RIGHTS)
            .roomSpareParts(UPDATED_ROOM_SPARE_PARTS);
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(updatedRoomTransactionProperty);

        restRoomTransactionPropertyMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomTransactionPropertyDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
        RoomTransactionProperty testRoomTransactionProperty = roomTransactionPropertyList.get(roomTransactionPropertyList.size() - 1);
        assertThat(testRoomTransactionProperty.getListingTime()).isEqualTo(UPDATED_LISTING_TIME);
        assertThat(testRoomTransactionProperty.getLastTradeTime()).isEqualTo(UPDATED_LAST_TRADE_TIME);
        assertThat(testRoomTransactionProperty.getRoomAgeLimit()).isEqualTo(UPDATED_ROOM_AGE_LIMIT);
        assertThat(testRoomTransactionProperty.getRoomMortgage()).isEqualTo(UPDATED_ROOM_MORTGAGE);
        assertThat(testRoomTransactionProperty.getRoomTransactionOwnership()).isEqualTo(UPDATED_ROOM_TRANSACTION_OWNERSHIP);
        assertThat(testRoomTransactionProperty.getRoomUser()).isEqualTo(UPDATED_ROOM_USER);
        assertThat(testRoomTransactionProperty.getRoomPropertyRights()).isEqualTo(UPDATED_ROOM_PROPERTY_RIGHTS);
        assertThat(testRoomTransactionProperty.getRoomSpareParts()).isEqualTo(UPDATED_ROOM_SPARE_PARTS);
    }

    @Test
    @Transactional
    void putNonExistingRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomTransactionPropertyDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                put(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomTransactionPropertyWithPatch() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();

        // Update the roomTransactionProperty using partial update
        RoomTransactionProperty partialUpdatedRoomTransactionProperty = new RoomTransactionProperty();
        partialUpdatedRoomTransactionProperty.setId(roomTransactionProperty.getId());

        partialUpdatedRoomTransactionProperty.lastTradeTime(UPDATED_LAST_TRADE_TIME);

        restRoomTransactionPropertyMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomTransactionProperty.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomTransactionProperty))
            )
            .andExpect(status().isOk());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
        RoomTransactionProperty testRoomTransactionProperty = roomTransactionPropertyList.get(roomTransactionPropertyList.size() - 1);
        assertThat(testRoomTransactionProperty.getListingTime()).isEqualTo(DEFAULT_LISTING_TIME);
        assertThat(testRoomTransactionProperty.getLastTradeTime()).isEqualTo(UPDATED_LAST_TRADE_TIME);
        assertThat(testRoomTransactionProperty.getRoomAgeLimit()).isEqualTo(DEFAULT_ROOM_AGE_LIMIT);
        assertThat(testRoomTransactionProperty.getRoomMortgage()).isEqualTo(DEFAULT_ROOM_MORTGAGE);
        assertThat(testRoomTransactionProperty.getRoomTransactionOwnership()).isEqualTo(DEFAULT_ROOM_TRANSACTION_OWNERSHIP);
        assertThat(testRoomTransactionProperty.getRoomUser()).isEqualTo(DEFAULT_ROOM_USER);
        assertThat(testRoomTransactionProperty.getRoomPropertyRights()).isEqualTo(DEFAULT_ROOM_PROPERTY_RIGHTS);
        assertThat(testRoomTransactionProperty.getRoomSpareParts()).isEqualTo(DEFAULT_ROOM_SPARE_PARTS);
    }

    @Test
    @Transactional
    void fullUpdateRoomTransactionPropertyWithPatch() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();

        // Update the roomTransactionProperty using partial update
        RoomTransactionProperty partialUpdatedRoomTransactionProperty = new RoomTransactionProperty();
        partialUpdatedRoomTransactionProperty.setId(roomTransactionProperty.getId());

        partialUpdatedRoomTransactionProperty
            .listingTime(UPDATED_LISTING_TIME)
            .lastTradeTime(UPDATED_LAST_TRADE_TIME)
            .roomAgeLimit(UPDATED_ROOM_AGE_LIMIT)
            .roomMortgage(UPDATED_ROOM_MORTGAGE)
            .roomTransactionOwnership(UPDATED_ROOM_TRANSACTION_OWNERSHIP)
            .roomUser(UPDATED_ROOM_USER)
            .roomPropertyRights(UPDATED_ROOM_PROPERTY_RIGHTS)
            .roomSpareParts(UPDATED_ROOM_SPARE_PARTS);

        restRoomTransactionPropertyMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomTransactionProperty.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomTransactionProperty))
            )
            .andExpect(status().isOk());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
        RoomTransactionProperty testRoomTransactionProperty = roomTransactionPropertyList.get(roomTransactionPropertyList.size() - 1);
        assertThat(testRoomTransactionProperty.getListingTime()).isEqualTo(UPDATED_LISTING_TIME);
        assertThat(testRoomTransactionProperty.getLastTradeTime()).isEqualTo(UPDATED_LAST_TRADE_TIME);
        assertThat(testRoomTransactionProperty.getRoomAgeLimit()).isEqualTo(UPDATED_ROOM_AGE_LIMIT);
        assertThat(testRoomTransactionProperty.getRoomMortgage()).isEqualTo(UPDATED_ROOM_MORTGAGE);
        assertThat(testRoomTransactionProperty.getRoomTransactionOwnership()).isEqualTo(UPDATED_ROOM_TRANSACTION_OWNERSHIP);
        assertThat(testRoomTransactionProperty.getRoomUser()).isEqualTo(UPDATED_ROOM_USER);
        assertThat(testRoomTransactionProperty.getRoomPropertyRights()).isEqualTo(UPDATED_ROOM_PROPERTY_RIGHTS);
        assertThat(testRoomTransactionProperty.getRoomSpareParts()).isEqualTo(UPDATED_ROOM_SPARE_PARTS);
    }

    @Test
    @Transactional
    void patchNonExistingRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomTransactionPropertyDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomTransactionProperty() throws Exception {
        int databaseSizeBeforeUpdate = roomTransactionPropertyRepository.findAll().size();
        roomTransactionProperty.setId(count.incrementAndGet());

        // Create the RoomTransactionProperty
        RoomTransactionPropertyDTO roomTransactionPropertyDTO = roomTransactionPropertyMapper.toDto(roomTransactionProperty);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomTransactionPropertyMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomTransactionPropertyDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomTransactionProperty in the database
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomTransactionProperty() throws Exception {
        // Initialize the database
        roomTransactionPropertyRepository.saveAndFlush(roomTransactionProperty);

        int databaseSizeBeforeDelete = roomTransactionPropertyRepository.findAll().size();

        // Delete the roomTransactionProperty
        restRoomTransactionPropertyMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomTransactionProperty.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomTransactionProperty> roomTransactionPropertyList = roomTransactionPropertyRepository.findAll();
        assertThat(roomTransactionPropertyList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
